package com.lewis.controller;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.lewis.entry.User;
import com.lewis.service.ShiroServiceImpl;

/**
 * 密码加密注册
 * 登陆验证
 * @author jiaqi.liu
 *
 */
@RestController
public class ShiroController {
	
	
	@Resource
	private ShiroServiceImpl shiroServiceImpl;
	
	/**
	 * 测试注册加密
	 * @param user
	 * @throws Exception 
	 */
	@PostMapping("/register")
	public void testRegister(@RequestBody User user) throws Exception{
		
		shiroServiceImpl.doRegister(user);
	}
	

	/**
	 * test login
	 * @return
	 */
	@RequestMapping("/doLogin")
	public String  testLogin(@RequestBody(required=false) User user){
		
		if(user==null) return "not log in";
		try{
			shiroServiceImpl.doLogin(user);
			
		}catch(Exception e){
			return e.getMessage();
		}
		return "";
	}
	
	@GetMapping("/login")
	public String loging(){
		throw new RuntimeException("catch controller exception!!!!");
	}
}
